package com.casic.ops.controller;

import com.casic.ops.annotation.RestWrapper;
import com.casic.ops.consts.history.HistoryValueType;
import com.casic.ops.entity.domain.OpsResult;
import com.casic.ops.entity.request.HistoryValueRequest;
import com.casic.ops.entity.vo.HistoryValueVO;
import com.casic.ops.service.api.HistoryValueService;
import com.casic.ops.utils.OpsAssert;
import com.orion.lang.wrapper.HttpWrapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ops-platform
 * @Description 历史值
 * @Author mianbin
 * @Date 2022/5/31 10:58
 * @Version 1.0
 **/
@RestController
@RestWrapper
@RequestMapping("/ops/api/history-value")
public class HistoryValueController {

    @Resource
    private HistoryValueService historyValueService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public OpsResult<List<HistoryValueVO>> list(@RequestBody HistoryValueRequest request) {
        OpsAssert.notNull(request.getValueId());
        OpsAssert.notNull(HistoryValueType.of(request.getValueType()));
        return historyValueService.list(request);
    }

    /**
     * 回滚
     */
    @RequestMapping("/rollback")
    public HttpWrapper<?> rollback(@RequestBody HistoryValueRequest request) {
        Long id = OpsAssert.notNull(request.getId());
        historyValueService.rollback(id);
        return HttpWrapper.ok();
    }

}
